import { Controller, Get, Post, Body, Res, Param, Delete } from '@nestjs/common';
import { CollectService } from './collect.service';

type Data = {
  user_id: string,
  food_id: string
}
@Controller('collect')
export class CollectController {
  constructor(private readonly collectService: CollectService) { }

  @Post()
  async creact(@Body() body: Data, @Res() res) {
    const result = await this.collectService.creact(body)
    if (!result) {
      res.status(428).send({
        status: 428,
        message: "收藏失败"
      })
    } else {
      res.send({
        status: 200,
        message: "收藏成功"
      })
    }
  }
  @Delete()
  async delectOne(@Body() body: Data, @Res() res) {
    const result = await this.collectService.delectOne(body)
    if (!result) {
      res.status(429).send({
        status: 429,
        message: "取消失败"
      })
    } else {
      if (result.deletedCount == 1) {
        res.status(200).send({
          status: 200,
          message: "取消成功"
        })
      } else {
        res.status(429).send({
          status: 429,
          message: "取消失败"
        })
      }
    }
  }
  @Get('/user/collect/:id')
  async useCollect(@Param() param, @Res() res) {
    const result = await this.collectService.useCollect(param.id)
    res.status(200).send({
      status: 200,
      message: "获取成功",
      data: result
    })
  }
  @Post('/getone')
  async getOne(@Body() body: Data, @Res() res) {
    const result = await this.collectService.getOne(body)
    console.log(result)
    if (!result) {
      res.status(201).send({
        message: "未发现",
        status: 201
      })
    } else {
      res.status(200).send({
        message: "成功",
        status: 200
      })
    }
  }
  @Get('/list/:id/:skip')
  async getList(@Param() Param, @Res() res) {
    console.log(Param, 'ss')
    const result = await this.collectService.getList(Param.id, Param.skip)
    res.status(200).send({
      status: 200,
      message: "获取成功",
      data: result
    })
  }
}
